package cn.jane.bigevent.mapper;

import cn.jane.bigevent.entity.Article;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface ArticleMapper {

    @Insert("""
            INSERT INTO article (title, content, cover_img, state, category_id, create_user, create_time, update_time)
            VALUES (#{title}, #{content}, #{coverImg}, #{state}, #{categoryId}, #{createUser}, #{createTime}, #{updateTime})
            """)
    void add(Article article);

    List<Article> list(Integer categoryId, String state, int userId);

    @Select("""
            SELECT * FROM article WHERE id = #{id}
            """)
    Article findById(int id);

    @Update("""
            UPDATE article SET
                title = #{title}, content = #{content}, cover_img = #{coverImg},
                state = #{state}, category_id = #{categoryId}, update_time = #{updateTime}
            WHERE id = #{id}
            """)
    void update(Article article);

    @Delete("""
            DELETE FROM article WHERE id = #{id}
            """)
    void delete(int id);
}
